
(function(){
    //Initialize Select2 Elements
    $(".select2").select2();
    $("#province_id").select2();
    var area_type = $("#area_type").select2();
    var city_select2 = $("#city_id").select2();
    $("#province_id").on("select2:select", function(e){
        console.log($(this).val());
        var p_id = $(this).val();
        area_type.val(1).trigger("change");
        if (p_id > 0) {
            area_type.val(2).trigger("change");
            $.ajax({
                method: "GET",
                url: "/"+admin_site_area+"/content/area/ajax_area_data",
                data: {p_id:p_id}
            }).done(function(data){
                // console.log(data);
                $("#city_id").html(data);
                city_select2.val(0).trigger("change");
            })
        } else {
            $("#city_id").html('<option selected="selected" value="0">可选择</option>');
            city_select2.val(0).trigger("change");
        }
    });
    $("#city_id").on("select2:select", function(e){
        var p_id = $(this).val();
        area_type.val(2).trigger("change");
        if (p_id > 0) {
            area_type.val(3).trigger("change");
        }
    });

    $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
      checkboxClass: 'icheckbox_minimal-blue',
      radioClass: 'iradio_minimal-blue'
    });
    
    //鼠标移入列表出现编辑与删除
    $(".item").mouseover(function(){
            $(this).find(".edit_tab").show();
        });

    $(".item").mouseout(function(){
            $(this).find(".edit_tab").hide();
        });
    //选择城市模式切换
    $(".choose_tab").change(function(){
        var type = $(this).val();
        if(type == 2){
            window.location.href= "/"+admin_site_area+"/content/area/index/all";    
        }
        if(type == 1){
            window.location.href= "/"+admin_site_area+"/content/area/index/active";
        }
    });

})();